Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backfill Blobs #13595

Merged
merged 9 commits into from
Feb 14, 2024
Merged

Backfill Blobs #13595

merged 9 commits into from
Feb 14, 2024

Conversation

kasey
Copy link
Contributor

@kasey kasey commented Feb 7, 2024

What type of PR is this?

Feature

What does this PR do? Why is it needed?

This PR adds the ability to sync blobs while backfilling blocks. This is a requirement for prysm nodes started from checkpoint sync to fulfill the promise of data availability. It's also puts us back in compliance with the p2p rpc specs which requires us to serve blocks up to MIN_EPOCHS_FOR_BLOCK_REQUESTS, and blobs up to MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS. Being unable to fulfill these responsibilities could hurt the peer score of prysm nodes and degrade network performance.

Which issues(s) does this PR fix?

Fixes #13029

@kasey kasey marked this pull request as ready for review February 9, 2024 15:44
@kasey kasey requested a review from a team as a code owner February 9, 2024 15:44
@kasey kasey requested review from nalepae, potuz and nisdas February 9, 2024 15:44
@kasey kasey changed the title WIP: Backfill Blobs Backfill Blobs Feb 9, 2024
@kasey kasey force-pushed the backfill-blobs branch 2 times, most recently from 6155179 to 5279dd1 Compare February 10, 2024 21:03
func (b batch) blobRequest() *eth.BlobSidecarsByRangeRequest {
return &eth.BlobSidecarsByRangeRequest{
StartSlot: b.begin,
Count: uint64(b.end - b.begin),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is b.end > b.begin requirement verified somewhere?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be implicitly done in the before method of the batcher

return len(bs.expected) - bs.next
}

func (bs *blobSync) validateNext(rb blocks.ROBlob) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this function need any unit test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will mostly piggy back on the tests of the verification package but I could add some additional coverage.

return len(bs.expected) - bs.next
}

func (bs *blobSync) validateNext(rb blocks.ROBlob) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do we verify the blob's slot?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -27,7 +58,7 @@ type verifier struct {
}

// TODO: rewrite this to use ROBlock.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this TODO comment still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it's referring to the input parameter.

backfillBlobsApproximateBytes.Add(float64(sz))
log.WithFields(b.logFields()).WithField("dlbytes", sz).Debug("backfill batch blob bytes downloaded")
}
if b.blobsNeeded() > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this panic if b.bs is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not possible the way it's currently written but good idea to check it for future proofing.

Copy link
Contributor Author

@kasey kasey Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way to get into this func is if state is batchBlobSync, and I've changed the code so the only way to get into that state and set the value for batchh.results is to also set the batch.bs via withResults. I think that makes calling a func that assumes batch.bs is not nil safe. This can be improved with some more refactoring after I get the clock initialization overhaul done.

beacon-chain/sync/backfill/batch.go Outdated Show resolved Hide resolved
beacon-chain/sync/backfill/blobs.go Outdated Show resolved Hide resolved
if err != nil {
return nil, err
}
if bytesutil.ToBytes48(vb.KzgCommitment) != bytesutil.ToBytes48(c[i]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: is this better than !bytes.Equal? I think ToBytes48 allocates memory while bytes.Equal casts to string to compare in place

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can also just do [48]byte(vb.KzgCommitment) != [48]byte(c[i]) .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do. i'll use bytes.Equal because I'm scared to cast to an array (ToBytes48 does padding for safety so it's not totally equivalent to casting to the underlying array).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

beacon-chain/sync/backfill/metrics.go Outdated Show resolved Hide resolved
@@ -251,6 +243,16 @@ func New(cliCtx *cli.Context, cancel context.CancelFunc, opts ...Option) (*Beaco
beacon.verifyInitWaiter = verification.NewInitializerWaiter(
beacon.clockWaiter, forkchoice.NewROForkChoice(beacon.forkChoicer), beacon.stateGen)

pa := peers.NewAssigner(beacon.fetchP2P().Peers(), beacon.forkChoicer)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the reason to change the ordering here ?

Copy link
Contributor Author

@kasey kasey Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because backfill service now depends on initwaiter (ie blob validation), which depends on stategen, which depends on backfill db. stategen depends on the backfill database (to check if a given slot is available), but not on the rest of backfill. So first we init the backfill db, then stategen and blob verification, then the backfill service. This is why the backfill db coverage package and db init is separate, to avoid circularity.

func (b batch) blobRequest() *eth.BlobSidecarsByRangeRequest {
return &eth.BlobSidecarsByRangeRequest{
StartSlot: b.begin,
Count: uint64(b.end - b.begin),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be implicitly done in the before method of the batcher

if err != nil {
return nil, err
}
if bytesutil.ToBytes48(vb.KzgCommitment) != bytesutil.ToBytes48(c[i]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can also just do [48]byte(vb.KzgCommitment) != [48]byte(c[i]) .

@kasey kasey force-pushed the backfill-blobs branch 4 times, most recently from c346815 to 45ec5ae Compare February 14, 2024 05:07
nisdas
nisdas previously approved these changes Feb 14, 2024
Copy link
Member

@terencechain terencechain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@kasey kasey enabled auto-merge February 14, 2024 20:44
@kasey kasey added this pull request to the merge queue Feb 14, 2024
Merged via the queue into develop with commit bb66201 Feb 14, 2024
17 checks passed
@kasey kasey deleted the backfill-blobs branch February 14, 2024 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

blob backfilling
5 participants